package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemPostService;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {

    @Autowired
    private SystemPostService systemPostService;
    @Resource
    private SystemUserMapper systemUserMapper;

    //根据条件分页查询后台用户列表
    @Override
    public IPage<SystemUserItemVo> findSystemUserItemVoPage(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.findSystemUserItemVoPage(page,queryVo);
    }
    //根据id查询后台用户信息
    @Override
    public SystemUserItemVo findSystemUserItemVoById(Long id) {
        //1.获取该id对应的SystemUser
        SystemUser systemUser = this.getById(id);
        //2.获取该systemUser对应的postId(岗位id)
        Long postId = systemUser.getPostId();
        //3.获取systemUser对应的岗位的名称
        String postName = systemPostService.getById(postId).getName();
        //4.组装对象，并返回
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        BeanUtils.copyProperties(systemUser,systemUserItemVo);
        systemUserItemVo.setPostName(postName);
        //5.返回前，将密码这个属性设置为空，不返回密码数据，保证安全性
        systemUserItemVo.setPassword(null);
        return systemUserItemVo;
    }
}




